package fnord.jovian.tango;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;

import javax.swing.*;

import fnord.jovian.TheBoard;

public class TheTextArea implements TheObject {
	
	private JTextArea _text;
	private JScrollPane _pane;

	public TheTextArea(double w, double h, TheBoard board) {
        _text = new JTextArea();
        
        _text.setLineWrap(true);
        _text.setWrapStyleWord(true);
        _text.setBorder(javax.swing.BorderFactory.createEmptyBorder());
        _text.setEditable(false);
        _text.setFont(new java.awt.Font("Times", java.awt.Font.BOLD, 12));
		_text.setBorder(BorderFactory.createLineBorder(TheTangoConstants.GRAY,1));
		_text.setBackground(TheTangoConstants.GRAY);
		_text.setForeground(Color.WHITE);

        _pane = new JScrollPane(_text);
        _pane.setSize((int)w,(int)h);
		_pane.setBorder(BorderFactory.createLineBorder(TheTangoConstants.GRAY,1));
        
        board.add(_pane);
        
	}

	public void addText(String text) {
		_text.append(text + "\n");
        _text.setCaretPosition(_text.getText().length());
	}
	
	public String getText() {
		return _text.getText();
	}
	
	public void clearText() {
		_text.setText("");
	}
	
    public void paint(Graphics2D g) {}

	public boolean contains(Point p) {
	    return false;
    }

    public boolean containsClick(Point p) {
	    return false;
    }

    public boolean containsDrag(Point p) {
	    return false;
    }

    public boolean containsUp(Point p) {
	    return false;
    }

    public double getX() {
		return _pane.getX();
    }

    public double getY() {
		return _pane.getY();
    }

    public double getCenterX() {
	    // TODO Auto-generated method stub
		return _pane.getX() - _pane.getWidth()/2;
    }

    public double getCenterY() {
		return _pane.getY() - _pane.getHeight()/2;
    }

    public void setLocation(double x, double y) {
		_pane.setLocation((int)x,(int)y);
    }

    public double getWidth() {
	    return _pane.getWidth();
    }

    public double getHeight() {
	    return _pane.getHeight();
    }

	@Override
    public void setSize(double w, double h) {
	    _pane.setSize((int)w,(int)h);
    }
	
	public void setActive(boolean active) {
		if (!active) {
			_pane.setBorder(BorderFactory.createLineBorder(TheTangoConstants.DARK_GRAY,1));
			_text.setBorder(BorderFactory.createLineBorder(TheTangoConstants.DARK_GRAY,1));
			_text.setBackground(TheTangoConstants.DARK_GRAY);
		}
		else {
			_pane.setBorder(BorderFactory.createLineBorder(TheTangoConstants.GRAY,1));
			_text.setBorder(BorderFactory.createLineBorder(TheTangoConstants.GRAY,1));
			_text.setBackground(TheTangoConstants.GRAY);
		}
	}
	
}
